package com.gaohe.web.controller.dcp;

import com.gaohe.common.annotation.Log;
import com.gaohe.common.core.controller.BaseController;
import com.gaohe.common.core.domain.AjaxResult;
import com.gaohe.common.core.page.TableDataInfo;
import com.gaohe.common.enums.BusinessType;
import com.gaohe.common.utils.poi.ExcelUtil;
import com.gaohe.dcp.domain.DcpScale;
import com.gaohe.dcp.service.IDcpScaleService;
import com.sun.tools.jconsole.JConsoleContext;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 量表管理Controller
 *
 * @author ruoyi
 * @date 2025-04-23
 */
@RestController
@RequestMapping("/dcp/scale")
public class DcpScaleController extends BaseController
{
    @Autowired
    private IDcpScaleService dcpScaleService;

    /**
     * 查询量表管理列表
     */
    @PreAuthorize("@ss.hasPermi('dcp:scale:list')")
    @GetMapping("/list")
    public TableDataInfo list(DcpScale dcpScale)
    {
        startPage();
        List<DcpScale> list = dcpScaleService.selectDcpScaleList(dcpScale);
        return getDataTable(list);
    }

    /**
     * 导出量表管理列表
     */
    @PreAuthorize("@ss.hasPermi('dcp:scale:export')")
    @Log(title = "量表管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DcpScale dcpScale)
    {
        List<DcpScale> list = dcpScaleService.selectDcpScaleList(dcpScale);
        ExcelUtil<DcpScale> util = new ExcelUtil<DcpScale>(DcpScale.class);
        util.exportExcel(response, list, "量表管理数据");
    }

    /**
     * 获取量表管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('dcp:scale:query')")
    @GetMapping(value = "/{scaleId}")
    public AjaxResult getInfo(@PathVariable("scaleId") Long scaleId)
    {
        return success(dcpScaleService.selectDcpScaleByScaleId(scaleId));
    }

    /**
     * 新增量表管理
     */
    @PreAuthorize("@ss.hasPermi('dcp:scale:add')")
    @Log(title = "量表管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DcpScale dcpScale)
    {
        return toAjax(dcpScaleService.insertDcpScale(dcpScale));
    }

    /**
     * 修改量表管理
     */
    @PreAuthorize("@ss.hasPermi('dcp:scale:edit')")
    @Log(title = "量表管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DcpScale dcpScale)
    {
        return toAjax(dcpScaleService.updateDcpScale(dcpScale));
    }

    /**
     * 删除量表管理
     */
    @PreAuthorize("@ss.hasPermi('dcp:scale:remove')")
    @Log(title = "量表管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{scaleIds}")
    public AjaxResult remove(@PathVariable Long[] scaleIds)
    {
        return toAjax(dcpScaleService.deleteDcpScaleByScaleIds(scaleIds));
    }

    //全查
    @PreAuthorize("@ss.hasPermi('dcp:scale:list')")
    @GetMapping("/listScales")
    public TableDataInfo listScales()
    {
        List<DcpScale> list = dcpScaleService.getDcpScaleList();
        return getDataTable(list);
    }

    //改状态   王浩宇
    @PreAuthorize("@ss.hasPermi('dcp:scale:edit')")
    @PutMapping("/changeScale")
    public AjaxResult changeStatus(@RequestBody DcpScale dcpScale){
        dcpScale.setUpdateBy(getUsername());
        return toAjax(dcpScaleService.changeStatus(dcpScale));
    }

}
